@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/js/axios.js"></script>
    <style>
        * {
            box-sizing: border-box;
        }

        .slider {
            width: 560px;
            height: 400px;
            overflow: hidden;
        }

        .slider-wrapper {
            width: 100%;
            height: 320px;
        }

        .slider-wrapper img {
            width: 100%;
            height: 100%;
            display: block;
        }

        .slider-footer {
            height: 80px;
            background-color: rgb(100, 67, 68);
            padding: 12px 12px 0 12px;
            position: relative;
        }

        .slider-footer .toggle {
            position: absolute;
            right: 0;
            top: 12px;
            display: flex;
        }

        .slider-footer .toggle button {
            margin-right: 12px;
            width: 28px;
            height: 28px;
            appearance: none;
            border: none;
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
            border-radius: 4px;
            cursor: pointer;
        }

        .slider-footer .toggle button:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .slider-footer p {
            margin: 0;
            color: #fff;
            font-size: 18px;
            margin-bottom: 10px;
        }

        .slider-indicator {
            margin: 0;
            padding: 0;
            list-style: none;
            display: flex;
            align-items: center;
        }

        .slider-indicator li {
            width: 8px;
            height: 8px;
            margin: 4px;
            border-radius: 50%;
            background: #fff;
            opacity: 0.4;
            cursor: pointer;
        }

        .slider-indicator li.active {
            width: 12px;
            height: 12px;
            opacity: 1;
        }
    </style>
</head>

<body>
<div class="slider">
    <div class="slider-wrapper">
        <img src="" alt=""/>
    </div>
    <div class="slider-footer">
        <p>对人类来说会不会太超前了？</p>
        <ul class="slider-indicator">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <div class="toggle">
            <!-- 上一张 -->
            <button class="prev">&lt;</button>
            <!-- 下一张 -->
            <button class="next">&gt;</button>
        </div>
    </div>
</div>
<script>
    (function () {

        axios({
            method: "get",
            url: "/Image/getImages"
        }).then(function ({data: res}) {
            if (res.code === 200) {
                let sliderData = [];
                sliderData = res.data;
                console.log(sliderData);
                const img = document.querySelector(".slider-wrapper img");
                const p = document.querySelector(".slider-footer p");
                const footer = document.querySelector(".slider-footer");
                const list = document.querySelectorAll(".slider-indicator li"); // 获取了所有的li
                const prev = document.querySelector(".prev"); // 上一张
                const next = document.querySelector(".next"); // 下一张
                const slider = document.querySelector(".slider"); // 最外层的盒子
                let index = 0;
                // 上一张
                prev.addEventListener("click", function () {
                    index--;
                    index = index < 0 ? sliderData.length - 1 : index
                    toggle();
                })
                // 下一张
                next.addEventListener("click", function () {
                    index++;
                    index = index > sliderData.length ? 0 : index;
                    toggle();
                })
                // 图片切换
                function toggle() {
                    const result = sliderData[index];
                    img.src = result.imageName;
                    // p.innerHTML = result.title;
                    footer.style.backgroundColor = result.color;
                    document.querySelector(".slider-indicator .active").classList.remove("active");
                    list[index].classList.add("active");
                }
                // 鼠标移动到最外层盒子，停止图片的切换。
                slider.addEventListener("mouseenter", function () {
                    clearInterval(tId);
                });
                let tId = setInterval(function () {
                    next.click();// 调用了下一张按钮的click函数，调用一次click函数作用，就相当于单击了一次下一张按钮。
                }, 1000);
                // 鼠标离开最外层的盒子，重新开启自动切换播放
                slider.addEventListener("mouseleave", function () {
                    if (tId) {
                        clearInterval(tId);
                    }
                    tId = setInterval(function () {
                        next.click();
                    }, 1000);
                })
            }
        })
    }())
</script>

</body>

</html>